#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "HRibbonMainWindow.h"
#include <BundleFrameworkFactory.h>
#include <BundleFramework.h>
#include <BundleException.h>
#include <IBundleContext.h>
#include <QStackedWidget>
#include <QActionGroup>
#include <QDesktopWidget>
#include <QHash>
#include <QLabel>
#include <QPropertyAnimation>
#include "imainframeservice.h"

class HRibbonCategory;
class HRibbonContextCategory;
class HRibbonCustomizeWidget;
class QTextEdit;
class HRibbonActionsManager;
class HRibbonStackedWidget;
class HRibbonGalleryGroup;

class MainWindow : public HRibbonMainWindow,public IMainFrameService
{
    Q_OBJECT
    Q_INTERFACES(IMainFrameService)

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    /// 初始化标题栏
    void initTitleBar();

    /// 加载菜单配置文件
    void loadMenuConfig();

    /// 加载插件
    void loadPlugins();

    // QObject interface
protected:
    void timerEvent(QTimerEvent *event);

    // IMainFrameService interface
public:
    void addFrameAction(const QString &pageObjName, const QString &groupObjName, QAction *action, int mode);
    void addSmallWidget(const QString &pageName, const QString &groupName, QWidget *widget);
    void removeFrameAction(const QString &pageObjName, const QString &groupObjName, QAction *action);
    void addActionPage(const QString &pageObjName);
    void removeActionPage(const QString &pageObjName);
    void addActionGroup(const QString &pageObjName, const QString &groupObjName);
    void removeActionGroup(const QString &pageObjName, const QString &groupObjName);
    int addFrameCenterWidget(QWidget *widget);
    void removeFrameCenterWidget(QWidget *widget);
    QDockWidget *addFrameDockWidget(QWidget *widget,Qt::DockWidgetArea area = Qt::LeftDockWidgetArea);
    int addFrameDockCenterWidget(QWidget* pwidget);
    QStackedWidget *getCenterWidget();
    QMainWindow *getBaseWindow();
    IDataManager *getDataManager();

private slots:
    void slot_minMaxRibbonBar(bool);
    void slot_minMaxVoicePan(bool);
    void slot_showCentralView(bool);
    void onStyleClicked(int id);
    void slot_generateBundle();
    void slot_IconTranslate();
    void slot_exit();

    void slot_newProject();
    void slot_loadProject();
    void slot_exportProject();
    void slot_saveAsProject();
    void slot_SystemConfigActionTriggered();

private:
    HRibbonStackedWidget* mpCenterWidget = nullptr;
    HRibbonStackedWidget* mpDockCenterWidget = nullptr;

    // 插件框架相关
    PluginFrameworkFactory          m_frameWorkFactory;
    QSharedPointer<BundleFramework> m_framework;
    QList<QSharedPointer<IBundle> > m_loadedPlugins;
    QVector<QPair<QString, bool>>   m_pluginsLoaded;

    QActionGroup* mpOperatorActionGroup = nullptr;
    QLabel* mpTimeLabel = nullptr;
    QPropertyAnimation* mpVoiceWidgteAnimation = nullptr;

};
#endif // MAINWINDOW_H
